import React, { Children, useContext, useEffect } from "react";
import { PropsWithChildren, useState } from "react";

const CountContext = React.createContext<{
  count: number;
  setCount: (i: number) => void;
} | null>(null);

export const CountContextProvider:React.FC<PropsWithChildren<{}>> = ({children}) => {
  // 初始化的时候 boolean 为false，会自动减1，所以将其初始化为1
  const [count,setCount] = useState<number>(1)

  return <CountContext.Provider value={{count,setCount}}>
    {children}
  </CountContext.Provider>
}

export const useCountContext = () => useContext(CountContext)!